how i write a 0`s or 1`s to binary file in bits not in bytes how can i do that

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amgad atef
    New Member
    • Aug 2014
    • 1

    how i write a 0`s or 1`s to binary file in bits not in bytes how can i do that

    how i write a 0`s or 1`s to binary file in bits not in bytes how can i do that
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    you could use bit fields to pack bits into a byte then write the byte to a binary file

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You don't even need bit fields. Use an unsigned int. A 5 is a binary 101. In a 32-bit unsigned int the bits would be 000000000000000 000000000000001 01. If you write the int, that's the binary pattern in your file.

      All you need do is find the integer value that matches the bit pattern you want and write that out.

      You can never write just one bit. The I/O is byte sized.

      Comment

      Working...